/** @file gui_list.h
 */
#ifndef	_LIST_H_
#define	_LIST_H_

#include "widget.h"
#include "stdlib.h"

class ListItem
{
public:
    ListItem(char *t_name);
    ~ListItem(){};

    ListItem *next;
    ListItem *prev;
    void operator delete(void *t){port_free( t);}
    void *operator new(unsigned int len){return port_malloc(len);}
    int index;
    char *name;
private:
};

typedef enum {
    SIGNAL_LIST_CHANGED=0,
    SIGNAL_LIST_LEAVE_FOCUS,
    SIGNAL_LIST_MAX
} list_signal;

class List: public Widget
{
public:
    List(HWND parent=0);
    ~List();

    int index;
    int max_index;
    void addItem(char* name);
    void setIndex(int index);
    int getIndex();
    void setFont(FONT * font);

    Signal signal[SIGNAL_LIST_MAX];
private:
    int keyShift;
    ListItem *itemList;
    ListItem *getFirstItem(ListItem **list){return *list;}
    bool isListVacant(ListItem **list){return *list==0?1:0;}
    void insertItem(ListItem **list, ListItem *item);
    void removeItem(ListItem **list, ListItem *item);

    void indexUp();
    void indexDown();

    FONT *font;
    virtual int eventHandler(HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam);
    virtual void draw(Rect *r);
    void setupWidgets();
    char* getText();
    virtual void leaveFocus(){signal[SIGNAL_LIST_LEAVE_FOCUS].emitSignal();}
};


#endif


